# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from django.shortcuts import render

# Create your views here.
from django.shortcuts import render
from django.http import HttpResponseRedirect,HttpResponse
from .models import Users
from .forms import LoginForm,UsersForm
# Create your views here.


def login(request):
    # a = Users.objects.get(pk=410861)
    form=LoginForm() ##实列化空表单
    if request.method== 'POST':  ##判断请求类型
        logger = logging.getLogger('django')
        form=LoginForm(request.POST)  ##创建有数据的表单对象
        if form.is_valid():  ##验证数据
            # new_f = form.save(commit=False)
            subject = form.cleaned_data['mobile']
            message = form.cleaned_data['money']
            sender = form.cleaned_data['password']
            # return HttpResponseRedirect('/thanks/')  ##重定向
    # else:
        # form = UsersForm(instance=a)
    return render(request, 'blogs/login.html', {'form':form})  ##渲染模板


def tvalidtae(request):
    logger = logging.getLogger('django')
    form=UsersForm() ##实列化空表单
    if request.method== 'POST':  ##判断请求类型
        form = UsersForm(request.POST)  ##创建有数据的表单对象
        if form.is_valid():  ##验证数据
            return render(request, 'blogs/login.html', {'form': form})  ##渲染模板
        else:
            logger.error(form.errors.as_json())
    return render(request, 'blogs/login.html', {'form':form})  ##渲染模板